import { configureStore } from "@reduxjs/toolkit";
import { useDispatch, TypedUseSelectorHook, useSelector } from "react-redux";
import { authSlice } from "@store/slices/authSlice"
import { apiSlice } from "@store/apiSlice";
import { authReducer } from "@store/slices/authSlice";
import { persistStore } from "redux-persist";
// 创建 store 对象
const store = configureStore({
  reducer: {
    [authSlice.name]: authSlice.reducer,authReducer,
    [apiSlice.reducerPath]: apiSlice.reducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat([apiSlice.middleware]),
});

// 获取 dispatch 方法的类型
export type AppDispatch = typeof store.dispatch;
// 用于获取带有类型的 dispatch 方法
export const useTypedDispatch = () => useDispatch<AppDispatch>();
// 获取 store 中管理的状态的类型
export type AppState = ReturnType<typeof store.getState>;
// 用于获取带有类型的 useSelector 方法
export const useTypedSelector: TypedUseSelectorHook<AppState> = useSelector;
// 默认导出 store 对象
export default store;
// 持久化状态对象
export const persistor = persistStore(store);